# Generated with SMOP  0.41
import numpy as np

# calNa.m




def calNa(s):
    n = s ** 2
    na = 0
    for i in range(1, int(np.ceil(0.16*n) + 1)):
        qi = calQi(i, s)
        p = max(np.ceil(np.log2(i)), 1)
        if n - 3 - p - qi < 0:
            na = i - 1
            break
        else:
            na = i
    return na


def calQi(i, s):
    qi = 0
    n = s ** 2
    for j in range(1, i + 1):
        qi += np.ceil(np.log2(n - j + 1))
    return qi
